<?php

namespace app\common\model;

use think\Model;

/**
 * 会员余额日志模型
 */
class MoneyLog Extends Model
{

    // 表名
    protected $name = 'user_money_log';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = '';
    // 追加属性
    protected $append = [
    ];

    //余额
    const MONEY = 1;
    //积分
    const SCORE = 2;
    //钱包类型
    public static function getTypeList()
    {
        return  [
            self::MONEY =>__("余额"),
            self::SCORE =>__("积分"),
        ];
    }

    //获取钱包类型
    public static function getTypeItem($value)
    {
        $list = self::getTypeList();
        if(isset($list[$value])){
            return  $list[$value];
        } else {
            return  " ";
        }
    }
    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    //后台添加
    const ADMIN_FROM_TYPE = 1;
    //商城购物
    const SHOP_FROM_TYPE = 2;
    //商城退款
    const SHOP_CANCEL_FROM_TYPE = 3;
    //充值余额
    const RECHARGE_MONEY = 4;
    //购买会员
    const BUY_VIP = 5;
    //购买课程送积分
    const BUY_COURSE_INTEGRAL = 6;
    //提现
//    const WITHDRAWAL = 5;

    //资金来源
    public static function getFromTypeList()
    {
        return  [
            self::ADMIN_FROM_TYPE =>__("后台添加"),
            self::SHOP_FROM_TYPE =>__("购买"),
            self::SHOP_CANCEL_FROM_TYPE =>__("退款"),
            self::RECHARGE_MONEY =>__("充值"),
            self::BUY_VIP =>__("购买会员"),
            self::BUY_COURSE_INTEGRAL =>__("购买课程送积分"),
//            self::WITHDRAWAL =>__("提现"),
        ];
    }

    //获取资金来源
    public static function getFromTypeItem($value)
    {
        $list = self::getFromTypeList();
        if(isset($list[$value])){
            return  $list[$value];
        } else {
            return  " ";
        }
    }

}
